<template>
  <a-card :bordered="false">
    <!-- 抽屉 -->
    <a-drawer title="设备详情" :width="screenWidth" @close="onClose" :visible="visible">
      <!-- 抽屉内容的border -->
      <div
        :style="{
          padding: '10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }"
      >
        <div class="table-page-search-wrapper">
          <a-form layout="inline" :form="form" @keyup.enter.native="searchQuery">
            <a-row :gutter="10">
              <a-col :md="12" :sm="12">
                <a-form-item label="设备编号"> {{ model.id }} </a-form-item>
              </a-col>
              <a-col :md="9" :sm="24">
                <a-form-item label="所属代理" style="width: 170px" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  {{ model.departName }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="10">
              <a-col :md="8" :sm="12">
                <a-form-item label="客户名称"> {{ model.clientName }} </a-form-item>
              </a-col>
              <a-col :md="9" :sm="24">
                <a-form-item label="硬件编号" style="width: 250px" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  {{ model.ids }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="10">
              <a-col :md="8" :sm="12">
                <a-form-item label="启用状态"> {{ model.enabled_dictText }} </a-form-item>
              </a-col>
              <a-col :md="9" :sm="24">
                <a-form-item label="租赁状态" style="width: 170px" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  {{ model.leasestate_dictText }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="10">
              <a-col :md="8" :sm="12">
                <a-form-item label="商品名称"> {{ model.commodityName }} </a-form-item>
              </a-col>
              <a-col :md="9" :sm="24">
                <a-form-item label="主板状态" style="width: 170px" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  {{ model.mainboard_dictText }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="10">
              <a-col :md="8" :sm="12">
                <a-form-item label="滤芯状态"> {{ model.filterelementType_dictText }} </a-form-item>
              </a-col>
              <a-col :md="9" :sm="24">
                <a-form-item
                  label="特殊地区损耗比例"
                  style="width: 170px"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                >
                  {{ model.lossratio }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="10">
              <a-col :md="10" :sm="12">
                <a-form-item label="备注"> {{ model.remarks }} </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div>
          <a-table
            ref="table"
            rowKey="id"
            size="middle"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange"
            :rowClassName="getRowClassname"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleReplace(record)">更换</a>
            </span>
          </a-table>
        </div>
      </div>
    </a-drawer>
    <!-- 字典数据 -->
  </a-card>
</template>

<script>
import pick from 'lodash.pick'
import { filterObj } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { replaceFilterelement } from '@api/api'
export default {
  name: 'EquipmentitemList',
  mixins: [JeecgListMixin],
  data() {
    return {
      columns: [
        {
          title: '滤芯名称',
          align: 'center',
          dataIndex: 'filterelementName',
        },
        {
          title: '可用天数',
          align: 'center',
          dataIndex: 'validity',
        },
        {
          title: '最低提醒天数',
          align: 'center',
          dataIndex: 'replacementdays',
        },
        {
          title: '已用天数',
          align: 'center',
          dataIndex: 'itTakesTime',
        },
        {
          title: '剩余可用天数',
          align: 'center',
          dataIndex: 'available',
        },
        {
          title: '是否提醒',
          align: 'center',
          dataIndex: 'remind_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      queryParam: {},
      title: '操作',
      visible: false,
      screenWidth: 800,
      //设备详情
      model: {},
      //设备id
      id: '',
      status: 1,
      labelCol: {
        xs: { span: 5 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 12 },
        sm: { span: 12 },
      },
      form: this.$form.createForm(this),
      url: {
        list: '/equipment/equipment/replaceList',
      },
    }
  },
  created() {
    // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
    this.resetScreenSize()
  },
  methods: {
    add(dictId) {
      debugger
      this.dictId = dictId
      this.edit({})
    },
    edit(record) {
      debugger
      this.id = record.id
      this.queryParam = {}
      this.model = Object.assign({}, record)
      this.showDrawer()
      // 当其它模块调用该模块时,调用此方法加载字典数据
      this.loadData()
    },
    //更换滤芯
    handleReplace(record) {
      //debugger
      var that = this
      //封装提交到后台的参数
      var param = {}
      param.recordId = record.id
      param.equipmentId = this.id
      replaceFilterelement(param).then(function (res) {
        if (res.success) {
          //成功就调用查询方法
          that.loadData()
          //成功刷新外面的页面
          this.$emit('ok')
        }
      })
    },
    getQueryParams() {
      //update--begin--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      this.ipagination.total = 0
      //update--end--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      var param = Object.assign({}, this.queryParam)
      param.id = this.id
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param)
    },

    // 添加字典数据

    showDrawer() {
      this.visible = true
    },
    onClose() {
      this.visible = false
      this.form.resetFields()
      this.dataSource = []
    },
    // 抽屉的宽度随着屏幕大小来改变
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 600) {
        this.screenWidth = screenWidth
      } else {
        this.screenWidth = 800
      }
    },
    //update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
    //增加样式方法返回值
    getRowClassname(record) {
      if (record.status == 0) {
        return 'data-rule-invalid'
      }
    },
    //update--end--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
  },
}
</script>
<style lang="less" scoped>
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
/deep/ .data-rule-invalid {
  background: #f4f4f4;
  color: #bababa;
}
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
</style>